﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using IStrong.EC.Abstractions.Interfaces;
using IStrong.EC.DAO.Abstractions.Interfaces;
using IStrong.EC.WebApi.Results.Entity;
using IStrong.EC.WebApi.Results.Entity.Daily;
using IStrong.EC.WebApi.Results.Entity.ViewModel;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace IStrong.EC.WebApi.Results.Repository
{
    public class WeixinusersRepository : IService
    {
        /// <summary>
        /// 数据库操作组件
        /// </summary>
        private readonly IDbContext _db;

        /// <summary>
        /// 配置信息
        /// </summary>
        private readonly IConfiguration _configuration;

        /// <summary>
        /// 日志组件
        /// </summary>
        private readonly ILogger<UserRep> _logger;

        /// <summary>
        /// 注入服务
        /// </summary>
        /// <param name="db"></param>
        /// <param name="configuration"></param>
        /// <param name="logger"></param>
        public WeixinusersRepository(IDbContext db, ILogger<UserRep> logger, IConfiguration configuration)
        {
            _db = db;
            _logger = logger;
            _configuration = configuration;
        }

        /// <summary>
        /// 根据Id获取用户信息
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public IEnumerable<UserInfoViewModel> GetUserInfos(object param)
        {
            return _db.Query<UserInfoViewModel>("Weixinusers.s_weixinusers", param);
        }

        /// <summary>
        /// 根据Id获取用户信息
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public IEnumerable<UserInfo> GetUserInfo(object param)
        {
            return _db.Query<UserInfo>("Weixinusers.s_wxusername_by_openid", param);
        }

        /// <summary>
        /// 添加/修改用户信息
        /// </summary>
        /// <param name="User"></param>
        /// <returns></returns>
        public int AddWeixinuser(Weixinusers Wxuser)
        {
            return _db.Execute("Weixinusers.i_weixinusers", Wxuser);
        }


    }
}
